package com.auth.sdk.transmit;

/**
 * Longin context transmit abstract
 *
 * @description: 登录态传播
 * @author: cyj
 * @date 2022 -08-11 14:54:16
 */
public interface LonginContextTransmitAbstract<T> {

    /**
     * Context transmit 运行并传播
     * 执行顺序: setLonginContext(t) -> transmit.execute() -> removeLonginContext()
     *
     * @param t        t
     * @param transmit transmit
     */
    default void contextTransmit(T t, Transmit transmit) {
        try {
            setLonginContext(t);
            if (null != transmit) {
                transmit.execute();
            }
        } finally {
            removeLonginContext();
        }
    }

    /**
     * Sets longin context *
     *
     * @param t t
     */
    void setLonginContext(T t);

    /**
     * Remove longin context
     */
    void removeLonginContext();

}
